package com.tiemei.featurehotsale.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.citrus.service.requestcontext.RequestContext;
import com.taobao.search.framework.DataComponent;
import com.taobao.search.framework.DataComponentRegistry;
import com.taobao.search.framework.DataModel;
import com.taobao.search.framework.servlet.AbstractSearchController;
import com.tiemei.featurehotsale.datamodel.PureDataModel;
import com.tiemei.featurehotsale.util.OnlyOneConstants;

/**
 * 唯一入口
 *
 * @author tiemei.jdk
 * @date   2012-10-30
 */
public class OnlyOneController<T extends PureDataModel> extends AbstractSearchController<PureDataModel> implements ApplicationContextAware{
	


    @Override
    protected void registerComponents(DataComponentRegistry registry) {
		registry.register(OnlyOneConstants.COMPONENT_TEMPLATESERVICE, getBean(OnlyOneConstants.COMPONENT_TEMPLATESERVICE));
    }
	
	
	/* ================================================================= */
	
	protected ApplicationContext applicationContext;
	
	@Override
	protected DataModel createDataModel(RequestContext requestContext) {
		return new PureDataModel(requestContext); 
	}
	
	@SuppressWarnings("unchecked")
    protected DataComponent getBean(String beanName){
    	return (DataComponent) applicationContext.getBean(beanName);
    }

	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}
	
}
